package com.inspur.myapplication.dao;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import com.inspur.myapplication.entity.UserBean;
import com.inspur.myapplication.util.ShoppingDbHelper;

/**
 * Created by Administrator on 2020/11/19.
 */

public class UserDao {
    private Context context;

    public UserDao(Context context){
        this.context=context;
    }
    public UserBean checkLogin(UserBean userBean){
        UserBean result=null;
        ShoppingDbHelper shoppingDbHelper=new ShoppingDbHelper(context);
        SQLiteDatabase sqLiteDatabase=shoppingDbHelper.getReadableDatabase();
        try {
            Cursor cursor=sqLiteDatabase.query("userInfotb",new String[]{"userid","username","password"},"username=? and password=?",new String[]{userBean.getUserName(),userBean.getPassword()},null,null,null);
            while (cursor.moveToNext()){
                result=new UserBean();
                String userId=cursor.getString(cursor.getColumnIndex("userid"));
                String username=cursor.getString(cursor.getColumnIndex("username"));
                String password=cursor.getString(cursor.getColumnIndex("password"));

                result.setUserId(userId);
                result.setPassword(password);
                result.setUserName(username);
            }
            cursor.close();

        }catch (Exception e){
            Log.e(UserDao.class.toString(),e.toString());
        }finally {
            sqLiteDatabase.close();
        }


        return result;
    }
}
